#! /bin/bash

# h_func written in bash shell script
#
#

q_perm_exec=q_perm_main

if ! [ -e $q_perm_exec ]
then
	echo "$q_perm_exec is not exits"
	exit 1
fi

if ! [ $1 ] || ! [ $2 ] || ! [ $3 ] || ! [ $4 ] || ! [ $5 ]
then
	echo "usage:$0 <num> <num> <num> <num> <num>"
	exit 1
fi

split_word()
{
	tmp_value=$1
	mask=255
	i=0
	while [ $i -lt 4 ]
	do
		tmp_bytes[$i]=$((tmp_value&mask))
		tmp_value=$((tmp_value>>8))
		echo "${tmp_bytes[$i]}"
		i=$((++i))
	done
	return 0
}

copy_array()
{
	source=$1
	dest=$2
	size=$3
	i=0
	while [ $i -lt $size ]
	do
		dest[$i]=${source[$i]}
		i=$((++i))
	done
	return 0
}

split_word $1 2
value_bytes=${tmp_bytes}
copy_array tmp_bytes value_bytes 4
i=0
while [ $i -lt 4 ]
do
	echo "${tmp_bytes[$i]}:${value_bytes[$i]}"
	i=$((++i))
done

for value in tmp_bytes
do
	echo $value
done
